home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / pcmag / v11n07 / demo_6.exe / DE6SRC.EXE / DEMO6.C < prev    next >
Text File  |  1992-02-08  |  16KB  |  380 lines

  1. // DEMO6.C --- Pen-centric Windows application that demonstrates 
  2. // handwritten input using the Recognize() function.
  3. // Copyright (C) 1992 Ray Duncan
  4.  
  5. #define WIN31
  6. #define dim(x) (sizeof(x) / sizeof(x[0]))   // returns no. of elements
  7. #define BUFMAX 80                           // size of scratch buffers
  8.  
  9. #include "windows.h"
  10. #include "penwin.h"
  11. #include "demo6.h"
  12.  
  13. HANDLE hInst;                               // instance handle
  14. HWND hWndFrame = 0;                         // frame window handle
  15. HWND hWndText = 0;                          // child text window handle
  16. HWND hWndWrite = 0;                         // child writing window handle
  17. HANDLE hPenWin = 0;                         // Pen Windows module handle
  18.  
  19. int CharX = 0;                              // average char width
  20. int CharY = 0;                              // char height
  21. int CurLine = 0;                            // current line number
  22. int MaxLine = 0;                            // maximum line number
  23. int EnumCount = 0;                          // translation counter
  24.  
  25. char szFrameClass[] = "DemoFrameClass";     // name of frame window class
  26. char szTextClass[]  = "DemoTextClass";      // child text window class
  27. char szWriteClass[] = "DemoWriteClass";     // child writing window class
  28.  
  29. struct {                                    // result codes returned
  30.     int Code;                               // by Recognize() function
  31.     char * Name;
  32.     } recogResults[] = {
  33.     REC_OK, "REC_OK",
  34.     REC_ABORT, "REC_ABORT",
  35.     REC_BADHPENDATA, "REC_BADHPENDATA",
  36.     REC_BUFFERTOOSMALL, "REC_BUFFERTOOSMALL",
  37.     REC_BUSY, "REC_BUSY",
  38.     REC_DONE, "REC_DONE",
  39.     REC_NOINPUT, "REC_NOINPUT",
  40.     REC_NOTABLET, "REC_NOTABLET",
  41.     REC_OOM, "REC_OOM",
  42.     REC_OVERFLOW, "REC_OVERFLOW",
  43.     REC_TERMBOUND, "REC_TERMBOUND",
  44.     REC_TERMEX, "REC_TERMEX",
  45.     REC_TERMOEM, "REC_TERMOEM",
  46.     REC_TERMPENUP, "REC_TERMPENUP",
  47.     REC_TERMRANGE, "REC_TERMRANGE",
  48.     REC_TERMTIMEOUT, "REC_TERMTIMEOUT", } ;
  49.  
  50. struct {                                    // result types returned
  51.     int Code;                               // in RCRESULT structure
  52.     char * Name;
  53.     } rctypeResults[] = {
  54.     RCRT_UNIDENTIFIED, "RCRT_UNIDENTIFIED",
  55.     RCRT_GESTURE, "RCRT_GESTURE",   
  56.     RCRT_NOSYMBOLMATCH, "RCRT_NOSYMBOLMATCH",    
  57.     RCRT_PRIVATE, "RCRT_PRIVATE",
  58.     RCRT_NORECOG, "RCRT_NORECOG",
  59.     RCRT_ALREADYPROCESSED, "RCRT_ALREADYPROCESSED",
  60.     RCRT_GESTURETRANSLATED, "RCRT_GESTURETRANSLATED",
  61.     RCRT_GESTURETOKEYS, "RCRT_GESTURETOKEYS", } ;
  62.  
  63. //
  64. // WinMain --- entry point from Windows.  Registers window classes,
  65. // creates windows, registers pen app, and processes messages until 
  66. // WM_QUIT received.
  67. //
  68. int PASCAL WinMain(HANDLE hInstance, 
  69.     HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  70. {
  71.     MSG msg;                     
  72.  
  73.     hInst = hInstance;                      // save this instance handle
  74.  
  75.     if(!hPrevInstance)                      // if first instance,
  76.         if(!InitApplication(hInstance))     // register window class
  77.             return(FALSE);                  // exit if couldn't register
  78.  
  79.     if(!InitInstance(hInstance, nCmdShow))  // create this instance's window
  80.     {
  81.         MessageBox(0, "Initialization failed!", "DEMO6", MB_OK|MB_ICONSTOP);
  82.         return(FALSE);
  83.     }
  84.  
  85.     RegisterPenApp(RPA_DEFAULT, TRUE);      // enable HEDIT/BEDIT controls
  86.  
  87.     while(GetMessage(&msg, NULL, 0, 0))     // while message != WM_QUIT
  88.     {
  89.         TranslateMessage(&msg);             // translate virtual key codes
  90.         DispatchMessage(&msg);              // dispatch message to window
  91.     }
  92.     return(msg.wParam);                     // return code = WM_QUIT value
  93. }
  94.  
  95. //
  96. // InitApplication --- registers window classes for this application
  97. //
  98. BOOL InitApplication(HANDLE hInstance)
  99. {
  100.     WNDCLASS  wc;
  101.     BOOL bParent;
  102.     BOOL bText;
  103.     BOOL bWrite;
  104.  
  105.     // set parameters for frame window class
  106.     wc.style = CS_HREDRAW | CS_VREDRAW;     // class style
  107.     wc.lpfnWndProc = FrameWndProc;           // class callback function
  108.     wc.cbClsExtra = 0;                      // extra per-class data
  109.     wc.cbWndExtra = 0;                      // extra per-window data
  110.     wc.hInstance = hInstance;               // handle of class owner
  111.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);     // default icon
  112.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);       // default cursor
  113.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); // background color 
  114.     wc.lpszMenuName =  "DemoMenu";          // name of menu resource
  115.     wc.lpszClassName = szFrameClass;        // name of window class
  116.  
  117.     bParent = RegisterClass(&wc);           // register frame window class
  118.  
  119.     // set parameters for text output child window class
  120.     wc.lpfnWndProc = TextWndProc;           // class callback function
  121.     wc.hIcon = NULL;                        // default icon
  122.     wc.lpszMenuName =  NULL;                // name of menu resource
  123.     wc.lpszClassName = szTextClass;         // name of window class
  124.  
  125.     bText = RegisterClass(&wc);             // register text child class
  126.  
  127.     // set parameters for writing input child window class
  128.     wc.lpfnWndProc = WriteWndProc;          // class callback function
  129.     wc.lpszClassName = szWriteClass;        // name of window class
  130.  
  131.     bWrite = RegisterClass(&wc);            // register writing child class
  132.  
  133.     return(bParent && bText && bWrite);     // return success/failure flag
  134. }
  135.  
  136. //
  137. // InitInstance --- creates frame window for this application instance
  138. //
  139. BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  140. {
  141.     hWndFrame = CreateWindow(               // create frame window
  142.         szFrameClass,                       // window class name
  143.         "Pen Windows Demo #6",              // text for title bar
  144.         WS_OVERLAPPEDWINDOW,                // window style
  145.         CW_USEDEFAULT, CW_USEDEFAULT,       // default position
  146.         CW_USEDEFAULT, CW_USEDEFAULT,       // default size
  147.         NULL,                               // no parent window
  148.         NULL,                               // use class default menu
  149.         hInstance,                          // window owner
  150.         NULL                                // unused pointer
  151.     );
  152.  
  153.     if(!hWndFrame) return(FALSE);           // error, can't create window
  154.  
  155.     ShowWindow(hWndFrame, nCmdShow);        // make frame window visible
  156.     UpdateWindow(hWndFrame);                // force WM_PAINT message
  157.     return(TRUE);                           // return success flag
  158. }
  159.  
  160. //
  161. // FrameWndProc --- callback function for application frame window
  162. //
  163. long FAR PASCAL FrameWndProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
  164. {
  165.     switch (wMsg) 
  166.     {
  167.         case WM_CREATE:                     // creating frame window
  168.             hWndText = CreateWindow(        // create child text window
  169.                 szTextClass,                // window class name
  170.                 NULL,                       // text for title bar
  171.                 WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER,    // style
  172.                 0, 0, 0, 0,                 // position and size
  173.                 hWnd,                       // frame window is parent 
  174.                 0,                          // child window identifier
  175.                 hInst,                      // window owner
  176.                 NULL);                      // unused pointer
  177.             hWndWrite = CreateWindow(       // create child writing window
  178.                 szWriteClass,               // window class name
  179.                 NULL,                       // text for title bar
  180.                 WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER,    // style
  181.                 0, 0, 0, 0,                 // position and size
  182.                 hWnd,                       // frame window is parent 
  183.                 0,                          // child window identifier
  184.                 hInst,                      // window owner
  185.                 NULL);                      // unused pointer
  186.             break;
  187.  
  188.         case WM_SIZE:                       // resize